import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SuccessfulEditOfProject {

    static WebDriver driver;
    static WebDriverWait wait;

    @BeforeClass
    public static void startFFDriverTest(){

        driver = FireFoxDriver.createFireFoxDriver();
        wait = new WebDriverWait(driver,10);
        Login loginPage = new Login(driver);
        loginPage.typeUserName();
        loginPage.typePassword();
        loginPage.clickSignIn(wait);
    }

    @Test
    public void editProject(){
        WebElement mainMenu= driver.findElement(By.id("navcontainer"));
        WebElement projectMenu = mainMenu.findElement(By.linkText("Projects"));
        projectMenu.click();
        new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::List Projects"));

        WebElement projectPane = driver.findElement(By.className("project-state-group"));
        WebElement EditProject = projectPane.findElement(By.className("edit_item"));
        EditProject.click();
        new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfElementLocated(By.id("edit_form_project_9")));

        WebElement projectEditForm = driver.findElement(By.id("edit_form_project_9"));
        WebElement EditProjectName = projectEditForm.findElement(By.id("project_name"));
        EditProjectName.clear();
        EditProjectName.sendKeys("New Project 1.3");

        WebElement editProjectDescription = projectEditForm.findElement(By.id("project_description"));
        editProjectDescription.clear();
        editProjectDescription.sendKeys("testingProject 1.3");

        WebElement editProjectStatus = projectEditForm.findElement(By.id("project_state_hidden"));
        editProjectStatus.click();

        WebElement editProjectSubmit = projectEditForm.findElement(By.id("submit_project_9"));
        editProjectSubmit.click();

        new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.linkText("New Project 1.3")));
    }

    @AfterClass
    public static void cleanUpTest(){
        driver.close();
        driver.quit();
    }
}
